﻿using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using CE.Database;

/// <summary>
/// Summary description for BrokerCallStatusDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class BrokerCallStatusDB
    {
        public BrokerCallStatusDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(BrokerCallStatus brokercallstatus)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocCXCICRMCallStatusInsertUpdateSingleItem]";
            SortedList _sPara = new SortedList();
            #region Parameter
            _sPara.Add("@CallStatusId", brokercallstatus.CallStatusId);
            _sPara.Add("@CECarId", brokercallstatus.CECarId);
            _sPara.Add("@CustomerId", brokercallstatus.CustomerId);
            _sPara.Add("@AgentId", brokercallstatus.AgentId);
            _sPara.Add("@CallStatus", brokercallstatus.AgentCallStatus);
            _sPara.Add("@CallTypeId", brokercallstatus.CallTypeId);
            _sPara.Add("@Remark", brokercallstatus.Remark);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);
            return _result;
        }

        public BrokerCallStatus GetCallStatus(Int64 CECarId, Int64 CustomerId)
        {
            BrokerCallStatus _mycallstatus = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocCXCICRMCallStatusSelectSingleItem]";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CECarId);
            _spara.Add("@CustomerId", CustomerId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _mycallstatus = new BrokerCallStatus();
                    _mycallstatus = FillDataRecord(_dt, 0);
                }
            }
            return _mycallstatus;
        }

        public BrokerCallStatus GetCallStatus(Int64 CECarId, Int64 CustomerId, Int32 CallTypeId)
        {
            BrokerCallStatus _mycallstatus = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocCXCICRMCallStatusSelectSingleItem]";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CECarId);
            _spara.Add("@CustomerId", CustomerId);
            _spara.Add("@CallTypeId", CallTypeId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _mycallstatus = new BrokerCallStatus();
                    _mycallstatus = FillDataRecord(_dt, 0);
                }
            }
            return _mycallstatus;
        }

        private BrokerCallStatus FillDataRecord(DataTable myDataTable, int RowId)
        {
            BrokerCallStatus myCallStatus = new BrokerCallStatus();
            myCallStatus.CallStatusId = Convert.ToInt64(myDataTable.Rows[RowId]["CallStatusId"].ToString());
            myCallStatus.CECarId = Convert.ToInt64(myDataTable.Rows[RowId]["CECarId"].ToString());
            myCallStatus.CustomerId = Convert.ToInt64(myDataTable.Rows[RowId]["CustomerId"].ToString());
            myCallStatus.AgentId = Convert.ToInt64(myDataTable.Rows[RowId]["AgentId"].ToString());
            myCallStatus.AgentCallStatus = Convert.ToInt32(myDataTable.Rows[RowId]["CallStatus"].ToString());
            myCallStatus.CallTypeId = Convert.ToInt32(myDataTable.Rows[RowId]["CallTypeId"].ToString());
            myCallStatus.Remark = myDataTable.Rows[RowId]["Remark"].ToString();
            myCallStatus.CreatedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["CreatedDate"].ToString());
            myCallStatus.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());
            return myCallStatus;
        }

    }
}